import math

# Optional format of the constructor for the OOP approach
class Player:
    def __init__(self):
        self.hunt_cost = -1.0
        self.opp_hunt_benefit = 3.0
		

    # All the other functions are the same as with the non object oriented setting (but they
    # should be instance methods so don't forget to add 'self' as an extra first argument).

    def hunt_choices(self, round_number, current_food, current_reputation, m, player_reputations):
		# hunt for the first rounds
		if (round_number <=2):
			hunt_decisions = ['h' for x in player_reputations]
			return hunt_decisions
		# if it's heads-up, slack
		
		rl = len(player_reputations)
		if (rl <2):
			hunt_decisions = ['s' for x in player_reputations]
			return hunt_decisions
		
		
		# compute a cumulative distribution for the inverse reputations, the count of (1-reputations) below (i+1)/rl
		pdf = [0 for i in range(rl+1)]
		for i in range(rl):
			index = int(math.floor((1.0-player_reputations[i]) * rl))
			pdf[index] += 1
			
		cdf = [0 for i in range(rl+1)]
		temp_total=0;
		for i in range(rl):
			temp_total+= pdf[i]
			cdf[i] = temp_total #inclusive scan
			
			
		# estimate the value of maintaining a reputation of i/(rl-1)  	
		hunt_value = [[self.hunt_cost * i + self.opp_hunt_benefit * cdf[i],i] for i in range(rl+1)]
			
		#find argmax hunt_value, which ranges from 0 to rl inclusive	
		hunt_value.sort()
		hunt_value.reverse()
		print hunt_value
		argmax_hunt_value = hunt_value[0][1]
		
		# sort player_reputations, keeping track of the original locations
		marked_reputations = [[player_reputations[i],i] for i in range(rl)]
		marked_reputations.sort()
		marked_reputations.reverse()
		
		# construct hunt_decisions, hunting with the players with the highest reputations
		hunt_decisions = ['s' for x in player_reputations]
		for i in range(argmax_hunt_value):
			high_rep_index = marked_reputations[i][1]
			hunt_decisions[high_rep_index] = 'h'
		
		return hunt_decisions

    def hunt_outcomes(self, food_earnings):
        pass # do nothing

    def round_end(self, award, m, number_hunters):
        pass # do nothing
		